{extend name="base"/}
{block name="resources"}
{/block}
{block name="main"}

<div class="layui-collapse ns-tips">
	<div class="layui-colla-item">
		<h2 class="layui-colla-title">操作提示</h2>
		<ul class="layui-colla-content layui-show">
			<li>店铺分类是指店铺的主营行业分类，前台会根据店铺的主营分类进行筛选。</li>
<!--			<li>不同店铺分类的保证金不同，会员申请入驻需要根据店铺分类缴纳相应的保证金。</li>-->
		</ul>
	</div>
</div>
<!-- 搜索框 -->
<div class="ns-single-filter-box">
	<button class="layui-btn ns-bg-color" onclick="clickAdd()">添加分类</button>

	<div class="layui-form">
		<div class="layui-input-inline">
			<input type="text" name="search_text" placeholder="请输入分类" autocomplete="off" class="layui-input">
			<button type="button" class="layui-btn layui-btn-primary" lay-filter="search" lay-submit>
				<i class="layui-icon">&#xe615;</i>
			</button>
		</div>
	</div>
</div>

<!-- 店铺主营列表 -->
<table id="category_info" lay-filter="category_info"></table>

<script type="text/html" id="category_id">
	{{#  layui.each(res.data, function(index, item){ }}
	<input type="checkbox" name="label_id" value="{{item.category_id}}"  />
	{{#  }); }}
</script>

<!-- 编辑删除操作 -->
<script type="text/html" id="action">
	<div class="ns-table-btn">
		<a class="layui-btn" lay-event="edit">编辑</a>
		<a class="layui-btn" lay-event="delete">删除</a>
	</div>
</script>
{/block}
{block name="script"}
<script>
layui.use(['form'], function() {
	var table,
		form = layui.form,
		repeat_flag = false;//防重复标识
		
	table = new Table({
		elem: '#category_info',
		url: ns.url("admin/shopcategory/lists"),
		cols: [
			[{
				unresize: 'false',
				field: 'category_name',
				title: '分类',
				width: '40%',
			}, /*{
				unresize: 'false',
				field: 'baozheng_money',
				title: '<span style="padding-right: 80px;">保证金（元）</span>',
				width: '30%',
				align: 'right',
				templet: function(data) {
					return '<span style="padding-right: 80px;">￥'+ data.baozheng_money +'</span>';
				}
			}, */{
				unresize: 'false',
				field: 'sort',
				title: '排序',
				width: '10%',
			}, {
				unresize: 'false',
				title: '操作',
				width: '20%',
				toolbar: '#action'
			}]
		],
	});
	
	/**
	* 监听工具栏操作
	*/
	table.tool(function(obj) {
		var data = obj.data;
		switch (obj.event) {
			case 'edit': //编辑
			location.href = ns.url("admin/shopcategory/editCategory?category_id="+ data.category_id)
				break;
			case 'delete': //删除
				deleteCategory(data.category_id);
				break;
		}
	});

	/**
	* 删除
	*/
	function deleteCategory(category_ids) {
		layer.confirm('确定要删除该分类吗？', function() {
			$.ajax({
				url: ns.url("admin/shopcategory/deleteCategory"),
				data: {category_ids: category_ids},
				dataType: 'JSON',
				type: 'POST',
				success: function(res) {
					layer.msg(res.message);
					repeat_flag = false;
					if (res.code == 0) {
						table.reload();
					}
				}
			});
		});
	}

	form.on('submit(search)', function(data){
		table.reload({
			page: {
				curr: 1
			},
			where: data.field
		});
	});
});

function clickAdd(){
	location.href = ns.url('admin/shopcategory/addCategory');
}
</script>
{/block}